<%@ page import="com.po.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    User user = (User) request.getAttribute("user");
%>
<a href="<%=request.getContextPath()%>/success.jsp">返回总页面</a>
<br><br><br><br><br>
<title>个人信息</title>
<div style="text-align: center">
    <span style="font-size: 24px;">
            <img class="bgImg" src="picture/chatBackground2.jpg"><br>
    </span>
    <style>
        .bgImg{
            border-radius: 150px;
            width: 300px;
            height: 300px;
            background: url("picture/ecosphereBlack.jpg");
            background-size: 300px;
        }
    </style>
    <from>
        名字：<input type="text" value="<%=user.getName()%>" name="netName" id="netName" >
        <input value="更改名字" type="submit" onclick="modif()"><br>
        密码：<input type="text" placeholder="**********" name="password" id="password">
        <input type="submit" value="修改密码" onclick="modifPassword()">
    </from>
    </div>
<script type="text/javascript">
    let reg = /^[\u4E00-\u9FA5A-Za-z0-9]{1,10}$/;
    function modif(){
        let netName = document.getElementById("netName").value;
        const reg2 = /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$).{6,20}$/;
        if(!reg.test(netName)){
            alert("名字格式不对，数字英文中文一共不超过10个，不含有特殊字符");
        }
        var xmlHttp = new XMLHttpRequest();
        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                alert(xmlHttp.responseText);
                window.location.href='<%=request.getContextPath()%>/personalInformation';
            }
        }
        var param = "netName=" + netName;
        xmlHttp.open("post", "modifName?" + param, true);
        xmlHttp.send();
    }
    function modifPassword(){
        const password = document.getElementById("password").value;
        var xmlHttp = new XMLHttpRequest();
        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                alert(xmlHttp.responseText);
                window.location.href='<%=request.getContextPath()%>/personalInformation';
            }
        }
        var param = "password=" + password;
        xmlHttp.open("post", "modifPassword?" + param, true);
        xmlHttp.send();
    }
</script>
<style>
    body {
        background-image: url("picture/new.jpg");
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: center center;
        background-size: 100% 100%;
    }
</style>